﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace Agile.Redsys
{
    /// <summary>
    /// Class CommerceManager
    /// </summary>
    public static class CommerceManager
    {
        static CommerceManager()
        {
            List = new List<Commerce>();
        }

        /// <summary>
        /// Gets the registered commerces.
        /// </summary>
        /// <value>The registered commerces.</value>
        public static IList<Commerce> List { get; private set; }

        /// <summary>
        /// Registers the specified commerce.
        /// </summary>
        /// <param name="commerce">A commerce.</param>
        /// <exception cref="System.ArgumentException"></exception>
        public static void Register(Commerce commerce)
        {
            if (List.Any(x => x.Terminal == commerce.Terminal && x.MerchantCode == commerce.MerchantCode))
                throw new ArgumentException(string.Format("There is already a commerce with terminal {0} and code {1}.",
                                                          commerce.Terminal,
                                                          commerce.MerchantCode));

            List.Add(commerce);
        }
    }
}
